#include "http.h"
//张伟使用c13在此地进行了修改
#define TCP_DATA_BUFF_SIZE 4096
uint8_t TCP_BUFF[TCP_DATA_BUFF_SIZE];				                              	    /*定义一个1024的缓存*/
 http_config http_at24_data;
 void add_ip_to_http(u8* buffer);
 void add_socket_bound_to_http(u8* buffer);
 void change_usart_set(u8* buffer);
 void change_ip_set(u8* buffer);

void IP_transfrom_STR(u8 *IP,u8 *ip) ; //ip数字，IP字符串
#define TEXT_TEMPLATE_OK "HTTP/1.1 200 OK\r\n"\
"Content-Type: text/html\r\n"\
"Content-Length: %d\r\n"\
"Connection: keep_alive\r\n\r\n%s"
 
#define TEXT_TEMPLATE_ERR "HTTP/1.1 404 Not Found\r\n"\
"Content-Length: 0\r\n\r\n"\
"Connection: keep_alive\r\n\r\n"
 
//#define HTML_CONTENT "<!DOCTYPE html>"\
//"<html>"\
//"<head>"\
//"<meta charset=\"utf-8\">"\
//"<title>IP Config</title>"\
//"<style>"\
//".d-c{ position:absolute;left:35%;top:30%}"\
//"</style>"\
//"</head>"\
//"<body>"\
//"<div class=\"d-c\">"\
//"<p>System IP Config</p>"\
//"<p>NOW IP address is 192.168.010.203</p>"\
//"<form name=\"input\" action=\"sn_config.action\" method=\"post\">"\
//"NEW_IP:<input type=\"text\" name=\"sn\">"\
//"<input type=\"submit\" value=\"submit\">"\
//"</form>"\
//"</div>	"\
//"</body>"\
//"</html>\r\n"

static const char HTML_CONTENT[]=	

"<!DOCTYPE html>\
<html>\
<head>\
<meta charset=\"utf-8\">\
<title>116</title>\
</head>\
<body>\
    <h2>设置</h2>\
    <form action=\"/\" method=\"postIP\">\
      <label for=\"nameip\">IP地址:</label>\
        <input type=\"text\" id=\"nameip\" name=\"nameip\" value=\"192.168.10.203 \" required>\
        <br>\
        <input type=\"submit\" value=\"提交\">\
    </form>\
    <form action=\"/\" method=\"postusart\"> \
        <br>\
        <label><font style = \"color:red\">串口1设置:</font></label>\
        <br>\
        <label for=\"socket\">映射网络端口号:</label>\
        <input type=\"text\"id=\"socket\" name=\"socket1\" value=\"8123        \" required>\
        <br>\
        <label for=\"bound\">波特率:</label>\
        <input type=\"text\" id=\"bound\" name=\"bound1\" value=\"B115200       \" required>\
        <br>\
        <label for=\"data1\">数据位:</label>\
        <select id=\"data1\" name=\"data1\" >\
            <option value=\"17\"null17        >7</option>\
            <option value=\"18\"null18        >8</option>\
            <option value=\"19\"null19        >9</option>\
        </select>\
        <br>\
        <label for=\"stop1\">停止位:</label>\
        <select id=\"stop1\" name=\"stop1\" value=\"1\">\
            <option value=\"111\"null11           >1</option>\
            <option value=\"112\"null12         >1.5</option>\
            <option value=\"113\"null13           >2</option>\
        </select>\
        <br>\
        <label for=\"jiou1\">校验位:</label>\
        <select id=\"jiou1\" name=\"jiou1\" value=\"3\">\
            <option value=\"11\"nullji1       >奇</option>\
            <option value=\"12\"nullou1       >偶</option>\
            <option value=\"13\"nullwu1       >无</option>\
        </select>\
        <br> \
        <br> \
  <label><font style = \"color:red\">串口2设置:</font></label>\
  <br>\
  <label for=\"socket\">映射端口号:</label>\
  <input type=\"text\" id=\"socket\" name=\"socket2\" value=\"8124      \" required>\
  <br>\
  <label for=\"bound\">波特率:</label>\
  <input type=\"text\" id=\"bound\" name=\"bound2\" value=\"B9600      \" required>\
  <br>\
  <label for=\"data\">数据位:</label>\
  <select id=\"data\" name=\"data2\" value=\"8\">\
      <option value=\"27\"null27     >7</option>\
      <option value=\"28\"null28     >8</option>\
      <option value=\"29\"null29     >9</option>\
  </select>\
  <br>\
  <label for=\"stop\">停止位:</label>\
  <select id=\"stop\" name=\"stop2\" value=\"1\">\
      <option value=\"211\"null21      >1</option>\
      <option value=\"212\"null22     >1.5</option>\
      <option value=\"213\"null23      >2</option>\
  </select>\
  <br>\
  <label for=\"jiou\">校验位:</label>\
  <select id=\"jiou\" name=\"jiou2\" value=\"3\">\
      <option value=\"21\" nullji2      >奇</option>\
      <option value=\"22\" nullou2      >偶</option>\
      <option value=\"23\" nullwu2      >无</option>\
  </select>\
  <br>\
        <input type=\"submit\" value=\"提交\">\
    </form>\
    <form action=\"postusart\" method=\"postusart\">\
        <input type=\"submit\" value=\"重启并应用参数设置\">\
    </form>\
</body>\
</html>";

//#define  HTML_CONTENT  "<!DOCTYPE html>"\
//"<html>"\
//"<head>"\
//"<meta charset=\"utf-8\">?"\
//"<script>"\
//"function loadXMLDoc()"\
//"{"\
//"	var xmlhttp;"\
//"	if (window.XMLHttpRequest)"\
//"	{"\
//"		xmlhttp=new XMLHttpRequest();"\
//"	}"\
//"	else"\
//"	{"\
//"		xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");"\
//"	}"\
//"	xmlhttp.onreadystatechange=function()"\
//"	{"\
//"		if (xmlhttp.readyState==4 && xmlhttp.status==200)"\
//"		{"\
//"			document.getElementById(\"myDiv\").innerHTML=xmlhttp.responseText;"\
//"		}"\
//"	}"\
//"	xmlhttp.open(\"GET\",\"hello.bin\",true);"\
//"	xmlhttp.send();"\
//"}"\
//"</script>"\
//"</head>"\
//"<body>"\
//"<div id=\"myDiv\"><h2>使 AJAX 修用改该文本内容</h2></div>"\
//"<button type=\"button\" onclick=\"loadXMLDoc()\">修改内容</button>"\
//"</body>"\
//"</html>\r\n"




//#define  HTML_CONTENT  "<!DOCTYPE html>"\
//"<html>"\
//"<head>"\
//"<meta?charset=\"utf-8\">?"\
//"<title>菜鸟教程(runoob.com)</title>?"\
//"</head>"\
//"<body>"\
//"<h2>表单</h2>"\
//"<form action=\"/\" method=\"post\">"\
//"<!-- 文本输入框 -->"\
//"<label for=\"name\">用户名:</label>"\
//"<input type=\"text\" id=\"name\" name=\"name\" required>"\
//"<br>"\
//"<!-- 密码输入框 -->"\
//"<label for=\"password\">密码:</label>"\
//"<input type=\"password\" id=\"password\" name=\"password\" required>"\
//"<br>"\
//"<!-- 单选按钮 -->"\
//"<label>性别:</label>"\
//"<input type=\"radio\" id=\"male\" name=\"gender\" value=\"male\" checked>"\
//"<label for=\"male\">男</label>"\
//"<input type=\"radio\" id=\"female\" name=\"gender\" value=\"female\">"\
//"<label for=\"female\">女</label>"\
//"<br>"\
//"<!-- 复选框 -->"\
//"<input type=\"checkbox\" id=\"subscribe\" name=\"subscribe\" checked>"\
//"<label for=\"subscribe\">订阅推送信息</label>"\
//"<br>"\
//"<!-- 下拉列表 -->"\
//"<label for=\"country\">国家:</label>"\
//"<select id=\"country\" name=\"country\">"\
//"<option value=\"cn\">CN</option>"\
//"<option value=\"usa\">USA</option>"\
//"<option value=\"uk\">UK</option>"\
//"</select>"\
//"<br>"\
//"<!-- 提交按钮 -->"\
//"<input type=\"submit\" value=\"提交\">"\
//"</form>"\
//"</body>"\
//"</html>\r\n"


 
#define HTML_RESULT_OK "<!DOCTYPE html>"\
"<html>"\
"<head>"\
"<meta charset=\"utf-8\">"\
"<title>SN Config</title>"\
"<style>"\
".c-c{ position:absolute;left:40%;top:40%}"\
"</style>"\
"</head>"\
"<body>"\
"<div class=\"c-c\">"\
"<p>System Config OK</p>"\
"<p>retun to see new</p>"\
"</div>"\
"</body>"\
"</html>\r\n"
 
#define HTML_RESULT_ERR "<!DOCTYPE html>"\
"<html>"\
"<head>"\
"<meta charset=\"utf-8\">"\
"<title>SN Config</title>"\
"<style>"\
".c-c{ position:absolute;left:40%;top:49%}"\
"</style>"\
"</head>"\
"<body>"\
"<div class=\"c-c\">"\
"<p>System IP Config FAIL</p>"\
"</div>"\
"</body>"\
"</html>\r\n"


u8 func_analysis_http_request(u8* buffer, u16 len_recv, char* method, char* uri, char* data_body);
u8 func_package_http_response(u8* buffer, u16 *len_ret, u16 len_buf, char* cont, u16 len_cont);
u8 find_post_sn(u8* buffer,u16 len_recv,u8 *ip);
void IP_transfrom_IP_STR(u8 *IP,u8 *ip);
void IP_STR_transfrom_IP(u8 *IP,u8 *ip);   //IP_STR[40]==>ip[4]
void find_add_ip_to_http(u8* buffer, u8 *IP);
void find_add_newip_to_http(u8* buffer, u8 *IP);
u8 IP[40];
u8 ip[4];
u8 data[20];    //数字转换字符串缓冲区
u8 ip_set[40];

u8 res_code;

uint8_t listend3;
uint16_t len=0;
void HTTP_SET_TEST(void)
{	
	//u16 len=0;
	char http_method[16];
	char http_uri[64];
	char http_body[256];
	//u8 res_code;
 listend3=getSn_SR(SOCK_HTTP);
	switch(listend3)
		{
			case SOCK_CLOSED:
				socket(SOCK_HTTP, Sn_MR_TCP, 80, Sn_MR_ND);
				break;
			case SOCK_INIT:
				listen(SOCK_HTTP);
				break;		
			case SOCK_ESTABLISHED:	
				if((getPHYCFGR()&0x05)==0)//物理网口断开关闭连接
			  {
			     close(SOCK_HTTP);
			  }			
				if(getSn_IR(SOCK_HTTP) & Sn_IR_CON)
				{
					setSn_IR(SOCK_HTTP, Sn_IR_CON);
				}
				
  			len = getSn_RX_RSR(SOCK_HTTP);
				memset(TCP_BUFF, 0, TCP_DATA_BUFF_SIZE);
	  		len = recv(SOCK_HTTP, TCP_BUFF, len);
				if(len > 0)
				{
						res_code =func_analysis_http_request(TCP_BUFF, len, http_method, http_uri, http_body);
						
						if(res_code == 0)
						{
							memset(TCP_BUFF, 0, sizeof(TCP_BUFF));
							if(strcmp("GET", http_method) == 0)// &&strcmp("/", http_uri) == 0)
							{
								func_package_http_response (TCP_BUFF, &len, sizeof(TCP_BUFF),(char*) HTML_CONTENT, strlen(HTML_CONTENT));
							  add_ip_to_http(TCP_BUFF);
								add_socket_bound_to_http(TCP_BUFF);
								
								send(SOCK_HTTP, TCP_BUFF, len);					
							}
							else if(strcmp("POST", http_method) == 0)//&& strcmp("/sn_config.action", http_uri) == 0)
							{
			
								func_package_http_response(TCP_BUFF, &len, TCP_DATA_BUFF_SIZE, HTML_RESULT_OK, strlen(HTML_RESULT_OK));
								send(SOCK_HTTP, TCP_BUFF, len);
							}
							else
							{
								memcpy(TCP_BUFF, TEXT_TEMPLATE_ERR, strlen(TEXT_TEMPLATE_ERR));
								send(SOCK_HTTP, TCP_BUFF, strlen(TEXT_TEMPLATE_ERR));
							}
							disconnect(SOCK_HTTP);
						}
						else if(res_code == 2)
						{
						    change_usart_set(TCP_BUFF);
								memset(TCP_BUFF, 0, sizeof(TCP_BUFF));
								func_package_http_response(TCP_BUFF, &len, TCP_DATA_BUFF_SIZE, HTML_RESULT_OK, strlen(HTML_RESULT_OK));
								send(SOCK_HTTP, TCP_BUFF, len);
							
						}
						else if(res_code == 3)
						{
							  change_ip_set(TCP_BUFF);
								memset(TCP_BUFF, 0, sizeof(TCP_BUFF));
								func_package_http_response(TCP_BUFF, &len, TCP_DATA_BUFF_SIZE, HTML_RESULT_OK, strlen(HTML_RESULT_OK));
								send(SOCK_HTTP, TCP_BUFF, len);
							
						}
						else
						{
							memcpy(TCP_BUFF, TEXT_TEMPLATE_ERR, strlen(TEXT_TEMPLATE_ERR));
							send(SOCK_HTTP, TCP_BUFF, strlen(TEXT_TEMPLATE_ERR));
							disconnect(SOCK_HTTP);
						}
						memset(TCP_BUFF, 0, sizeof(TCP_BUFF));
					
					
				}
				break;
			  case SOCK_CLOSE_WAIT:
				  close(SOCK_HTTP);
				break;
				case  SOCK_FIN_WAIT:
				  close(SOCK_HTTP);
				break;
				default:
				if((getPHYCFGR()&0x05)==0)//物理网口断开关闭连接
			  {
			     close(SOCK_HTTP);
			  }	
				break;
		}

	
	
}


u8 func_analysis_http_request(u8* buffer, u16 len_recv, char* method, char* uri, char* data_body)
{
  char chs[20];
	memset(chs, 0, 20);
	char *res, *end;
	if(len_recv > 0)
	{
		memcpy(chs, buffer, 3);
		res = strstr(chs, "GET");
		if(strcmp("GET", res) == 0)
		{
		  
			memset(method, 0, 16);
			memcpy(method, "GET", strlen("GET"));
			
		}
		else
		{
			memset(chs, 0, 20);
			memcpy(chs, buffer, 4);
			res = strstr(chs, "POST");
			if(strcmp("POST", res) == 0)
			{
			
			  memset(method, 0, 16);
				memcpy(method, "POST", strlen("POST"));
		
			}
			else
			{
				return 1;
			}
		}
	 
	}

  memcpy(chs, buffer, 20);		
	res = strstr((char*)chs, "socket1");
	memcpy(chs, res, 7);
	memset(chs+7, 0,13);	
	//先读取数据头，看是不是有数据
  if(strcmp("socket1", chs) == 0)
  {
			
	  return 2;   //return 2表示有串口配置信息返回
		
  }
  memcpy(chs, buffer, 20);
 	res = strstr((char*)chs, "nameip");
	memcpy(chs, res, 6);
	memset(chs+6, 0,14);						
  if(strcmp("nameip", chs) == 0)
  {
			
	  return 3;   //return 2表示有ip配置信息返回
		
  }
	memcpy(chs, buffer, 20);		
	res = strstr((char*)chs, "postusart");
	memcpy(chs, res, 9);
	memset(chs+9, 0,11);	
	//先读取数据头，看是不是有数据
  if(strcmp("postusart", chs) == 0)
  {
		 memcpy(TCP_BUFF, TEXT_TEMPLATE_ERR, strlen(TEXT_TEMPLATE_ERR));
		 send(SOCK_HTTP, TCP_BUFF, strlen(TEXT_TEMPLATE_ERR));
		 disconnect(SOCK_HTTP);
		 disconnect(SOCK_USART1);
		 disconnect(SOCK_USART2);
		 close(SOCK_USART1);
		 close(SOCK_USART2);
		 close(SOCK_HTTP);
		
		 //GPIO_ResetBits(WIZ_SPIx_RESET_PORT, WIZ_RESET);
	   HAL_GPIO_WritePin(WIZ_SPIx_RESET_PORT, WIZ_RESET, GPIO_PIN_RESET);	
	   HAL_Delay(2000);
	   //GPIO_SetBits(WIZ_SPIx_RESET_PORT, WIZ_RESET);
     HAL_GPIO_WritePin(WIZ_SPIx_RESET_PORT, WIZ_RESET, GPIO_PIN_SET);
     HAL_Delay(2000);		
		 NVIC_SystemReset();
		 
	   return 4;   //直接重启
		
  }
	

	return 0;
}
 
u8 func_package_http_response(u8* buffer, u16 *len_ret, u16 len_buf, char* cont, u16 len_cont)
{
	memset(buffer, 0, TCP_DATA_BUFF_SIZE);
	*len_ret = sprintf((char*)buffer, TEXT_TEMPLATE_OK, len_cont, cont);
	//memcpy(len_ret, buffer, len_cont);
	return 0;
}

u8 find_post_sn(u8* buffer,u16 len_recv,u8 *ip)
{
  char chs[20] = {0, };
  char *res; //, *end;
	if(len_recv > 0)
	{

		res = strstr((char*)buffer, "sn=");
		memset(chs, 0, 20);
		memcpy(chs, res, 3);
		if(strcmp("sn=", chs) == 0)
		{
		    memset(ip, '.', 40);
        memcpy(ip, res+3, len_recv-(u16)(((u8*)res)-buffer)-3);
		}
	}
  return 0;
}
void find_add_newip_to_http(u8* buffer, u8 *IP)
{
       char *res; 
			 char chs[20] = {0, };
	     res = strstr((char*)buffer, "192.168.10.203");
			 memset(chs, 0, 20);
		   memcpy(chs, res, 14);
			 	if(strcmp("192.168.10.203", chs) == 0)
		   {
          memcpy(res,IP,15);
		   }
			 return;
}

void find_ip_to_http(u8* buffer, u8 *IP)
{
       char *res; 
			 char chs[100] = {0, };
	     res = strstr((char*)buffer, "The new ip is ");
			 memset(chs, 0, 20);
		   memcpy(chs, res, 14);
			 	if(strcmp("The new ip is ", chs) == 0)
		   {
          memcpy(res+14,IP,15);
		   }
			 return;
}

void IP_STR_transfrom_IP(u8 *IP,u8 *ip)
{
      u8  i=0;
			u8  j=0;
			u8 ip_set=0;
		  for (j=0;j<4;j++)
			{
			    ip_set=0;
					while (IP[i]!='.'&&(IP[i]>='0'&&IP[i]<='9')) 
					{
					   ip_set=ip_set*10;
						 if(IP[i]>='0'&&IP[i]<='9')
						 {
						     ip_set+=IP[i]-'0';
						 }
						 i++;
					}					
					ip[j]=ip_set;
					i++;
			}
			
		http_at24_data.IP[0]=ip[0];
		http_at24_data.IP[1]=ip[1];
		http_at24_data.IP[2]=ip[2];
		http_at24_data.IP[3]=ip[3];						
     return;
}
uint32_t STR_transfrom_uint(u8* str)
{
	    u8  i=0;		
			u32 ip_set=0;
		 
			    ip_set=0;
					while (str[i]!='.'&&(str[i]>='0'&&str[i]<='9')) 
					{
					   ip_set=ip_set*10;
						 if(str[i]>='0'&&str[i]<='9')
						 {
						     ip_set+=str[i]-'0';
						 }
						 if(i>10){return 0;}
						 i++;
						 
					}					
						
     return ip_set;


}

void IP_transfrom_IP_STR(u8 *IP,u8 *ip)
{
       ip[0]=local_ip[0];
			 ip[1]=local_ip[1];
       ip[2]=local_ip[2];
       ip[3]=local_ip[3];
    
														
       memset(IP, '.', 14);
			 

			 IP[0]='0'+ip[0]/100;
			 IP[1]='0'+ip[0]%100/10;
			 IP[2]='0'+ip[0]%10;
			 
			 IP[4]='0'+ip[1]/100;
			 IP[5]='0'+ip[1]%100/10;
			 IP[6]='0'+ip[1]%10;
			 
			 IP[8]='0'+  ip[2]/100;
			 IP[9]='0'+  ip[2]%100/10;
			 IP[10]='0'+ip[2]%10;
			 
			 IP[12]='0'+ip[3]/100;
			 IP[13]='0'+ip[3]%100/10;
			 IP[14]='0'+ip[3]%10;
			 
			 return;
}






void http_at24_data_init( void)
{
    http_at24_data.IP[0]=192;
		http_at24_data.IP[1]=168;
		http_at24_data.IP[2]=10;
		http_at24_data.IP[3]=203;
		
		http_at24_data.IP_SOCKET[0]=1190;
		http_at24_data.IP_SOCKET[1]=1191;
		
		http_at24_data.BOUND[0]=115200;
		http_at24_data.BOUND[1]=115200;
	
	  http_at24_data.data_len[0]=1;
		http_at24_data.data_len[1]=1; //数据位长度 0=7  1=8  2=9  
	
	  http_at24_data.data_check[0]=2;  
	  http_at24_data.data_check[1]=2; //校验位  0=ji 1=ou 2=无
	
		http_at24_data.data_stop[0]=0;  
	  http_at24_data.data_stop[1]=0;  //停止位 0=1 1=1.5 2=2
}


uint8_t dectochar(char ret[],uint32_t num)
{
    int i,j,k,sign;
    char tempc[20];
    i=0;
    do{
        tempc[i++]=num%10+'0';
			  if(i>10)
				{
				    return 1;
				}
    }
    while((num/=10)>0);
    tempc[i]=' ';
    ret[i]=' ';
    k=0;
    for(j=i-1;j>=0;j--)
    {
        ret[k]=tempc[j];
        k++;
    }
		return 0;
}

void IP_transfrom_STR(u8 *IP,u8 *ip)  //ip数字，IP字符串
{
    int i,j,k,sign;
		uint8_t num;
		
		 char tempc[20];
		 memset(tempc, ' ', 20);
			  i=0;
		for(int p=3;p>=0;p--)
		{
		     num=ip[p];
        do{
               tempc[i++]=num%10+'0';
					    if(i>16)
				      {
				        return ;
				      }
           }
          while((num/=10)>0);
		       tempc[i++]='.';
		}
		 tempc[i]=' ';
	
    IP[i]=' ';
    k=0;
    for(j=i-2;j>=0;j--)
    {
        IP[k]=tempc[j];
        k++;
    }
			return;
}


void add_ip_to_http(u8* buffer)
{
       char *res; 
			 char chs[20] = {0, };
	     res = strstr((char*)buffer, "192.168.10.203");
			 memset(chs, 0, 20);
		   memcpy(chs, res, 14);
			 	if(strcmp("192.168.10.203", chs) == 0)
		   {
			     memset(IP, ' ', 30);
			 
			     IP_transfrom_STR(IP,http_at24_data.IP);
					 
          memcpy(res,IP,15);
		   }
			 return;
}
void  add_socket_bound_to_http(u8* buffer)
{
		  char *res; 
			char chs[20] = {0, };
			//寻找标志位置
			res = strstr((char*)buffer, "8123");
			memset(chs, 0, 20);
		  memcpy(chs, res, 4);
			if(strcmp("8123", chs) == 0)
		  {
			     memset(data, ' ', 10);
			    
			     dectochar((char*)data,http_at24_data.IP_SOCKET[0]);  //socket1
					 
           memcpy(res,data,8);
		  }
			
			
			res = strstr((char*)buffer, "8124");
			memset(chs, 0, 20);			
		  memcpy(chs, res, 4);
			if(strcmp("8124", chs) == 0)
		  {
			     memset(data, ' ', 10);
			    
			     dectochar((char*)data,http_at24_data.IP_SOCKET[1]);  //socket2
					 
           memcpy(res,data,8);
		  }
			
			
			res = strstr((char*)buffer, "B115200");
			memset(chs, 0, 20);			
		  memcpy(chs, res, 7);
			if(strcmp("B115200", chs) == 0)
		  {
			     memset(data, ' ', 10);
			    
			     dectochar((char*)data,http_at24_data.BOUND[0]);  //USART1_BOUND
					 
           memcpy(res,data,10);
		  }
			
			res = strstr((char*)buffer, "B9600");
			memset(chs, 0, 20);			
		  memcpy(chs, res, 5);
			if(strcmp("B9600", chs) == 0)
		  {
			     memset(data, ' ', 10);
			    
			     dectochar((char*)data,http_at24_data.BOUND[1]);  //USART2_BOUND
					 
           memcpy(res,data,10);
		  }
			
//////////////////////////usart2 len//////////////////////////////////////			
			switch (http_at24_data.data_len[1])
			{
				case 0: 
					res = strstr((char*)buffer, "null27");
					memset(chs, 0, 20);			
					memcpy(chs, res, 6);
					if(strcmp("null27", chs) == 0)
					{
							 
							 memcpy(res,"selected",8);
					}		
				break;
				
				case 1:
					res = strstr((char*)buffer, "null28");
					memset(chs, 0, 20);			
					memcpy(chs, res, 6);
					if(strcmp("null28", chs) == 0)
					{

							memcpy(res,"selected",8);
					}	
					
				break;
				
				case 2:
          res = strstr((char*)buffer, "null29");
					memset(chs, 0, 20);			
					memcpy(chs, res, 6);
					if(strcmp("null29", chs) == 0)
					{
							memcpy(res,"selected",8);
					}						
					
				break;
        default:		break;
			}
//////////////////////////usart1_len////////////////////////			
			switch (http_at24_data.data_len[0])
			{
				case 0: 
					res = strstr((char*)buffer, "null17");
					memset(chs, 0, 20);			
					memcpy(chs, res, 6);
					if(strcmp("null17", chs) == 0)
					{
							 
							 memcpy(res,"selected",8);
					}		
				break;
				
				case 1:
					res = strstr((char*)buffer, "null18");
					memset(chs, 0, 20);			
					memcpy(chs, res, 6);
					if(strcmp("null18", chs) == 0)
					{
							memcpy(res,"selected",8);
					}	
					
				break;
				
				case 2:
          res = strstr((char*)buffer, "null19");
					memset(chs, 0, 20);			
					memcpy(chs, res, 6);
					if(strcmp("null19", chs) == 0)
					{
							memcpy(res,"selected",8);
					}						
					
				break;
        default:		break;
			}
/////////////////////usart1_stop//////////////////////
			switch (http_at24_data.data_stop[0])
			{
				case 0: 
					res = strstr((char*)buffer, "null11");
					memset(chs, 0, 20);			
					memcpy(chs, res, 6);
					if(strcmp("null11", chs) == 0)
					{							 
						  memcpy(res,"selected",8);
					}		
				break;
				
				case 1:
					res = strstr((char*)buffer, "null12");
					memset(chs, 0, 20);			
					memcpy(chs, res, 6);
					if(strcmp("null12", chs) == 0)
					{

							memcpy(res,"selected",8);
					}	
					
				break;
				
				case 2:
          res = strstr((char*)buffer, "null13");
					memset(chs, 0, 20);			
					memcpy(chs, res, 6);
					if(strcmp("null13", chs) == 0)
					{
							memcpy(res,"selected",8);
					}						
					
				break;
        default:		break;
			}	
////////////////////usart2_stop////////////////////
			switch (http_at24_data.data_stop[1])
			{
				case 0: 
					res = strstr((char*)buffer, "null21");
					memset(chs, 0, 20);			
					memcpy(chs, res, 6);
					if(strcmp("null21", chs) == 0)
					{
							 
							 memcpy(res,"selected",8);
					}		
				break;
				
				case 1:
					res = strstr((char*)buffer, "null22");
					memset(chs, 0, 20);			
					memcpy(chs, res, 6);
					if(strcmp("null22", chs) == 0)
					{

							memcpy(res,"selected",8);
					}	
					
				break;
				
				case 2:
          res = strstr((char*)buffer, "null23");
					memset(chs, 0, 20);			
					memcpy(chs, res, 6);
					if(strcmp("null23", chs) == 0)
					{
							memcpy(res,"selected",8);
					}						
					
				break;
        default:		break;
			}				
///////////////////////usart1_check//////////////////////				
	switch (http_at24_data.data_check[0])
			{
				case 0: 
					res = strstr((char*)buffer, "nullji1");
					memset(chs, 0, 20);			
					memcpy(chs, res, 7);
					if(strcmp("nullji1", chs) == 0)
					{						 
							 memcpy(res,"selected",8);
					}		
				break;
				
				case 1:
					res = strstr((char*)buffer, "nullou1");
					memset(chs, 0, 20);			
					memcpy(chs, res, 7);
					if(strcmp("nullou1", chs) == 0)
					{

							memcpy(res,"selected",8);
					}	
					
				break;
				
				case 2:
          res = strstr((char*)buffer, "nullwu1");
					memset(chs, 0, 20);			
					memcpy(chs, res, 7);
					if(strcmp("nullwu1", chs) == 0)
					{
							memcpy(res,"selected",8);
					}						
					
				break;
        default:		break;
			}		
//////////////////////////////////////////
switch (http_at24_data.data_check[1])
			{
				case 0: 
					res = strstr((char*)buffer, "nullji2");
					memset(chs, 0, 20);			
					memcpy(chs, res, 7);
					if(strcmp("nullji2", chs) == 0)
					{
						 
							 memcpy(res,"selected",8);
					}		
				break;
				
				case 1:
					res = strstr((char*)buffer, "nullou2");
					memset(chs, 0, 20);			
					memcpy(chs, res, 7);
					if(strcmp("nullou2", chs) == 0)
					{

							memcpy(res,"selected",8);
					}	
					
				break;
				
				case 2:
          res = strstr((char*)buffer, "nullwu2");
					memset(chs, 0, 20);			
					memcpy(chs, res, 7);
					if(strcmp("nullwu2", chs) == 0)
					{
							memcpy(res,"selected",8);
					}						
					
				break;
        default:		break;
			}				
			
			
			return;
}


void change_ip_set(u8* buffer)
{
  	char *res; 
		char chs[20] = {0, };
			//寻找标志位置
		res = strstr((char*)buffer, "nameip");
		memset(chs, 0, 20);
		memcpy(chs, res, 6);
		if(strcmp("nameip", chs) == 0)
		{
			  memset(data, 0, 20);
			  memcpy(data,res+7,15);
				IP_STR_transfrom_IP(data,ip);
		}
		AT24C02_save_data();
	

}

void change_usart_set(u8* buffer)
{
	  char *res; 
		char chs[20] = {0, };
			//寻找标志位置
		res = strstr((char*)buffer, "socket1");
		memset(chs, 0, 20);
		memcpy(chs, res, 7);
		if(strcmp("socket1", chs) == 0)
		{
			 memset(data, 0, 20);
			 memcpy(data,res+8,10);
			 http_at24_data.IP_SOCKET[0]= STR_transfrom_uint(data);
		}
		
		
		res = strstr((char*)buffer, "socket2");
		memset(chs, 0, 20);
		memcpy(chs, res, 7);
		if(strcmp("socket2", chs) == 0)
		{
			 memset(data, 0, 20);
			 memcpy(data,res+8,10);
			 http_at24_data.IP_SOCKET[1]= STR_transfrom_uint(data);
		}
//////////////////////////////////////////////////		
	  res = strstr((char*)buffer, "bound1");
		memset(chs, 0, 20);
		memcpy(chs, res, 6);
		if(strcmp("bound1", chs) == 0)
		{
			 memset(data, 0, 20);
			 memcpy(data,res+7,10);
			 http_at24_data.BOUND[0]= STR_transfrom_uint(data);
		}
		
		res = strstr((char*)buffer, "bound2");
		memset(chs, 0, 20);
		memcpy(chs, res, 6);
		if(strcmp("bound2", chs) == 0)
		{
			 memset(data, 0, 20);
			 memcpy(data,res+7,10);
			 http_at24_data.BOUND[1]= STR_transfrom_uint(data);
		}
////////////////////////////////////////////////////////
		 res = strstr((char*)buffer, "data1");
		memset(chs, 0, 20);
		memcpy(chs, res, 5);
		if(strcmp("data1", chs) == 0)
		{
			 memset(data, 0, 20);
			 memcpy(data,res+6,10);
			 http_at24_data.data_len[0]= STR_transfrom_uint(data)-17;
		}
		
		res = strstr((char*)buffer, "data2");
		memset(chs, 0, 20);
		memcpy(chs, res, 5);
		if(strcmp("data2", chs) == 0)
		{
			 memset(data, 0, 20);
			 memcpy(data,res+6,10);
			 http_at24_data.data_len[1]= STR_transfrom_uint(data)-27;
		}
/////////////////////////////////////////////////////////		
	  res = strstr((char*)buffer, "stop1");
		memset(chs, 0, 20);
		memcpy(chs, res, 5);
		if(strcmp("stop1", chs) == 0)
		{
			 memset(data, 0, 20);
			 memcpy(data,res+6,10);
			 http_at24_data.data_stop[0]= STR_transfrom_uint(data)-111;
		}
		
		res = strstr((char*)buffer, "stop2");
		memset(chs, 0, 20);
		memcpy(chs, res, 5);
		if(strcmp("stop2", chs) == 0)
		{
			 memset(data, 0, 20);
			 memcpy(data,res+6,10);
			 http_at24_data.data_stop[1]= STR_transfrom_uint(data)-211;
		}
///////////////////////////奇偶校验位///////////////////////////////
		  res = strstr((char*)buffer, "jiou1");
		memset(chs, 0, 20);
		memcpy(chs, res, 5);
		if(strcmp("jiou1", chs) == 0)
		{
			 memset(data, 0, 20);
			 memcpy(data,res+6,10);
			 http_at24_data.data_check[0]= STR_transfrom_uint(data)-11;
		}
		
		res = strstr((char*)buffer, "jiou2");
		memset(chs, 0, 20);
		memcpy(chs, res, 5);
		if(strcmp("jiou2", chs) == 0)
		{
			 memset(data, 0, 20);
			 memcpy(data,res+6,10);
			 http_at24_data.data_check[1]= STR_transfrom_uint(data)-21;
		}	
		AT24C02_save_data();
}
